package gui.admin;

import java.sql.SQLException;

import objects.Instructor;
import objects.School;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

import com.swtdesigner.SWTResourceManager;

public class AdminAboutPanelImpl extends AbstractAdminPanelImpl implements AdminAboutPanel {

	private Label ownerLbl;
	private Label mailingAddressLbl;
	private Label websiteLbl;
	private Label emailAddressLbl;
	private Label softwareVersionLbl;
	private Label copyrightLbl;
	private Label ownerName;
	private Label website;
	private Label address;
	private Label email;
	
	private Instructor instructor;

	public AdminAboutPanelImpl(Display display, Shell shell) {
		super(display, shell);
		
		instructor = new Instructor(1);
		try {
			database.getInstructor(instructor);
		} catch (SQLException e) {
			System.out.println("Unable to get Instructor");
			e.printStackTrace();
		}
	}

	public void open() {
		// remove at compile time
//		Shell shell = new Shell();
		// **********************
		
		shell.setSize(800, 600);
		shell.setText("About");
		
		ownerLbl = new Label(shell, SWT.NONE);
		ownerLbl.setBounds(10, 10, 95, 33);
		ownerLbl.setText("Owner:");
		ownerLbl.setFont(new Font(display, "Arial", 20, SWT.BOLD));
		
		mailingAddressLbl = new Label(shell, SWT.NONE);
		mailingAddressLbl.setBounds(10, 49, 221, 33);
		mailingAddressLbl.setText("Mailing Address:");
		mailingAddressLbl.setFont(new Font(display, "Arial", 20, SWT.BOLD));
		
		websiteLbl = new Label(shell, SWT.NONE);
		websiteLbl.setBounds(10, 152, 114, 33);
		websiteLbl.setText("Website:");
		websiteLbl.setFont(new Font(display, "Arial", 20, SWT.BOLD));
		
		emailAddressLbl = new Label(shell, SWT.NONE);
		emailAddressLbl.setBounds(10, 191, 202, 32);
		emailAddressLbl.setText("Email Address:");
		emailAddressLbl.setFont(new Font(display, "Arial", 20, SWT.BOLD));
		
		softwareVersionLbl = new Label(shell, SWT.NONE);
		softwareVersionLbl.setBounds(10, 229, 370, 33);
		softwareVersionLbl.setText("Software Version: Prototype");
		softwareVersionLbl.setFont(new Font(display, "Arial", 20, SWT.BOLD));
		
		copyrightLbl = new Label(shell, SWT.NONE);
		copyrightLbl.setText("Copyright \u00A9 2010 to Sentinel, Inc.");
		copyrightLbl.setBounds(172, 500, 440, 33);
		copyrightLbl.setFont(new Font(display, "Arial", 20, SWT.BOLD));
		
		ownerName = new Label(shell, SWT.NONE);
		ownerName.setForeground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_DARK_SHADOW));
		ownerName.setBounds(111, 10, 663, 33);
		ownerName.setFont(new Font(display, "Arial", 20, SWT.BOLD));
		
		website = new Label(shell, SWT.NONE);
		website.setForeground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_DARK_SHADOW));
		website.setBounds(130, 152, 644, 33);
		website.setFont(new Font(display, "Arial", 20, SWT.BOLD));
		
		address = new Label(shell, SWT.NONE);
		address.setForeground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_DARK_SHADOW));
		address.setBounds(237, 49, 537, 97);
		address.setFont(new Font(display, "Arial", 20, SWT.BOLD));
		
		email = new Label(shell, SWT.NONE);
		email.setForeground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_DARK_SHADOW));
		email.setBounds(218, 191, 556, 32);
		email.setFont(new Font(display, "Arial", 20, SWT.BOLD));

		// set Labels
		setOwnerName(instructor.getName());
		
		School temp = new School(instructor.getSchoolID());
		try {
			database.getSchool(temp);
		} catch (SQLException e) {
			System.out.println("Unable to get school");
			e.printStackTrace();
		}
		setAddress(temp.getAddress());
		setWebsite("http://www.cs.odu.edu/~411red");
		setEmail(instructor.getName() + "@cs.odu.edu");
		
		shell.open();
		shell.layout();
	}

	public void setOwnerName(String ownerName) {
		this.ownerName.setText(ownerName);
		this.ownerName.update();
	}

	public void setWebsite(String website) {
		this.website.setText(website);
		this.website.update();
	}

	public void setAddress(String address) {
		this.address.setText(address);
		this.address.update();
	}
	
	public void setEmail(String email) {
		this.email.setText(removeSpaces(email.toLowerCase()));
		this.email.update();
	}
}
